Skip to content

fix(sleep): read the learned block up to its own END marker - #480

Open
Lenin Mookiah (leninworld) wants to merge 1 commit into
microsoft:mainfrom
leninworld:fix-sleep-stray-learned-end-479
Open

Lenin Mookiah (leninworld) wants to merge 1 commit into
microsoft:mainfrom
leninworld:fix-sleep-stray-learned-end-479

Conversation

@leninworld

Copy link
Copy Markdown
Contributor

This PR fixes issue #479.

Summary

extract_learned in skillopt_sleep/memory.py read up to the first LEARNED END marker anywhere in the document, not the first one after the START marker. A stray END before the learned block (left by a merge conflict or a hand edit) made the block read as empty: current_learned_lines() returned [], and the next edit rewrote the block without the rules that were already adopted, while reporting the edit as applied. consolidate puts that document into the proposal, so adopting it drops those rules from the live file.

This is the mirror of the orphan START case fixed in #414 (#412). _strip_learned already searches for END after START.

Changes

  • extract_learned searches for the END marker after the START marker it found: doc.find(LEARNED_END, s + len(LEARNED_START)). A document with no START, or a START with no END after it, still reads as no learned items, as before.
  • CHANGELOG.md: entry under [Unreleased] → Fixed.

The stray END itself stays where it was, outside the block, like any other text of the user's.

Tests

New test_stray_end_before_learned_block_does_not_drop_adopted_rules in tests/test_learned_block_roundtrip.py (the reproduction from the issue): the adopted rule is read back, and after an add edit both the old rule and the new one are in the block. It fails on main (current_learned_lines(doc) is []) and passes with the fix.

  • python -m pytest -q tests/test_learned_block_roundtrip.py → 8 passed.
  • Full suite python -m pytest -q → 2617 passed, 23 skipped, 4 xfailed, 2 failed. The 2 failures are the tampered-manifest tests in tests/test_sleep_adopt_skill_subset.py, which fail the same way on main on this machine (macOS, Python 3.11).
  • ruff check skillopt_sleep/memory.py tests/test_learned_block_roundtrip.py → all checks passed.

Not changed here (same pattern, separate if you want them): extract_slow_update_field in skillopt/optimizer/slow_update.py and extract_slow_field in skillopt_sleep/slow_update.py also read to the first END marker anywhere.

Fixes #479

extract_learned searched for the first LEARNED END marker anywhere in
the document. A stray END before the learned block made the block read
as empty, and the next edit rewrote it without the adopted rules. Search
for END after the START marker, as _strip_learned already does.

Fixes microsoft#479

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sleep: a stray LEARNED END marker before the learned block makes the next edit drop the adopted rules

1 participant